package com.main.by.dao.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.main.by.dao.GeneralDao;
import com.main.by.dao.SubmitAndTaskDao;
import com.main.by.entity.vo.AdminLoginVO;
import com.main.by.entity.vo.SubmitAndTaskVO;

@Repository
public class SubmitAndTaskDaoImpl implements SubmitAndTaskDao{
	
Logger logger = Logger.getLogger(this.getClass());
	
	@Autowired
	private GeneralDao generalDao;

	@Override
	public List<SubmitAndTaskVO> findAll() throws Exception {
		return (List<SubmitAndTaskVO>) generalDao.findAllEntity(SubmitAndTaskVO.class, "select a.taskId, a.title,a.content,a.taskDesc, b.userName,c.submitId,"
				+ "c.taskPic,c.telphone,c.aliplay,c.bankPay,c.userQQ,c.blog,c.info,c.flag,c.submitDate from renren_task as a, renren_user as b, renren_submit as c where a.taskId = c.taskId and b.userId = c.userId and c.flag = 0");
	}

	@Override
	public boolean auditSubmitInfo(int submitInfoId) throws Exception {
		return generalDao.updateEntity("update renren_submit set flag=1 where submitId=? ",new Object[]{submitInfoId});
	}
	
	@Override
	public boolean deleteSubmitById(int submitId) throws Exception {
		return generalDao.updateEntity("delete from renren_submit where submitId=? ",new Object[]{submitId});
	}
	//查询已审核提交任务
	@Override
	public List<SubmitAndTaskVO> findAllAudited() throws Exception {
		return (List<SubmitAndTaskVO>) generalDao.findAllEntity(SubmitAndTaskVO.class, "select a.taskId, a.title,a.content,a.taskDesc, b.userName,c.submitId,"
				+ "c.taskPic,c.telphone,c.aliplay,c.bankPay,c.userQQ,c.blog,c.info,c.flag,c.submitDate from renren_task as a, renren_user as b, renren_submit as c where a.taskId = c.taskId and b.userId = c.userId and c.flag = 1");
	}
	
	@Override
	public SubmitAndTaskVO findSubmitAndTaskInfoById(int submitId) throws Exception {
		return generalDao.getEntity(SubmitAndTaskVO.class,new Object[]{submitId});
	}

}
